package com.zhangliuliu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhangliuliu.bean.AreaBean;
import com.zhangliuliu.bean.EventBean;
import com.zhangliuliu.service.EventService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;

@RestController
@RequestMapping("event")
public class eventController {
    @Resource
    private EventService eventService;

    @RequestMapping("add")
    @ResponseBody
    void addEvent(EventBean eventBean){
        eventService.addEvent(eventBean);
    }

    @RequestMapping("getAllById")
    @ResponseBody
    EventBean getAll(int id){
      return   eventService.getAll(id);
    }
    @RequestMapping("update")
    @ResponseBody
    void updateById(@RequestParam("id") int id, @RequestParam("stage") String stage, @RequestParam("plan") String plan){
        eventService.updateById(id,stage,plan);
    }
    IPage<EventBean> cutByItem(@RequestParam(value = "pageNo",defaultValue = "1") int pageNo,
                               @RequestParam(value = "pageSize",defaultValue = "4") int pageSize,
                               @RequestParam("name") String name,
                               @RequestParam("stage") String stage,
                               @RequestParam("location") AreaBean location,
                               @RequestParam("start") LocalDate start,
                               @RequestParam("end") LocalDate end){
        return eventService.cutByItem(pageNo,pageSize,name,stage,location,start,end);
    }
}
